import React, { Component } from 'react';
import { connect } from 'react-redux';
import $http from '../../http';
import Category from './components/Category';
import ProductList from './components/ProductList';

function mapStateToProps(state) {
    return {
        ...state
    };
}

function mapDispatchToProps(dispatch) {
    return {
        getList(){
            dispatch(()=>{
              $http.get('/api/list').then((res)=>{
                  console.log('api/list res',res);
                  dispatch({type:"SET_LIST",data:res.data})
              })


            })
        }

    };
}

class Cate1 extends Component {
    componentWillMount(){
        if(!this.props.loaded){
            this.props.getList();
        }
       
       
    }
    render() {
      let {category,list_cate}=this.props;
        return (
            <div>
               <h4>产品列表</h4>
                <div>
                 <div className="left">
                     <Category category={category}></Category>
                    </div> 
                 <div className="right">
                     <div>
                         <ProductList list={list_cate}></ProductList>
                        
                     </div>
                     </div> 
                </div>  
            </div>
        );
    }
}

export default connect(
    mapStateToProps,mapDispatchToProps
)(Cate1);